
using System;

using System.Collections.Generic;
using UnityEngine;

class test : MonoBehaviour
{

    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }
    LinkedList<int> link = new LinkedList<int>();
    //Stack<ListNode> stack = new Stack<ListNode>();

    void Start()
    {
        link.AddLast(3);
        link.AddLast(2);

        link.AddLast(1);
        link.AddLast(4);
        Debug.Log(ReversePrint(link.First));

    }
    public int[] ReversePrint(LinkedListNode<int> head)
    {

        Stack<LinkedListNode<int>> stack = new Stack<LinkedListNode<int>>();
        stack.Push(head);

        while (head.Next != null)
        {
            stack.Push(head.Next);
            head = head.Next;
        }

        int[] a = new int[stack.Count];
        for (int i = 0; i < stack.Count; i++)
        {

            Debug.Log("aaaaaaa"+stack.Count);
            a[i] = stack.Pop().Value;
            Debug.Log(a[i]);

        }


        return a;
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.Push(x);
 * obj.Pop();
 * int param_3 = obj.Top();
 * int param_4 = obj.Min();
 */